import { GxObejct } from "./GxObject";
export class GxTask extends GxObejct {
  completed: boolean;
  notes?: string;
  cTime?: string;
  sTime?: string;
  dTime?: string;
  expend?: string;
  constructor(options?: any) {
    super((options && options.id) || 0, (options && options.name) || "");
    this.completed = (options && options.completed) || false;
    this.notes = (options && options.notes) || "";
    this.cTime = (options && options.cTime) || "";
    this.sTime = (options && options.sTime) || "";
    this.dTime = (options && options.dTime) || "";
    this.expend = this.getExecuteTime();
  }
  public getExecuteTime(): string {
    if (this.sTime && this.dTime) {
      //将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式
      let startTime = this.sTime.replace(/\-/g, "/");
      let endTime = this.dTime.replace(/\-/g, "/");
      //将计算间隔类性字符转换为小写
      let sTime = new Date(startTime); //开始时间
      let eTime = new Date(endTime); //结束时间
      //作为除数的数字
      let timeDif: number = (eTime.getTime() - sTime.getTime()) / 1000;
      if (timeDif < 60) {
        return timeDif.toFixed(2) + "秒";
      } else if (timeDif > 59 && timeDif < 3600) {
        let val: string = (timeDif / 60).toFixed(2);
        return val + "分钟";
      } else if (timeDif >= 3599 && timeDif < 3600 * 24) {
        let val: string = (timeDif / (60*60)).toFixed(2);
        return val + "小时";
      } else if (timeDif > 3600 * 24 - 1) {
        let val: string = (timeDif / (3600 * 24)).toFixed(2);
        return val + "天";
      }
    }
    return "/";
  }
}
